import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("欢迎使用控制台计算器");
        System.out.println("请选择操作：");
        System.out.println("1. 加法 (+)");
        System.out.println("2. 减法 (-)");
        System.out.println("3. 乘法 (*)");
        System.out.println("4. 除法 (/)");
        System.out.println("5. 退出");

        while (true) {
            try {
                System.out.print("请输入操作编号(1/2/3/4/5): ");
                String choice = scanner.nextLine();

                if (choice.equals("5")) {
                    System.out.println("感谢使用计算器，再见！");
                    break;
                }

                if (!choice.matches("[1-4]")) {
                    System.out.println("无效输入，请重新选择");
                    continue;
                }

                System.out.print("请输入第一个数字: ");
                double num1 = Double.parseDouble(scanner.nextLine());

                System.out.print("请输入第二个数字: ");
                double num2 = Double.parseDouble(scanner.nextLine());

                switch (choice) {
                    case "1":
                        System.out.printf("结果: %.2f + %.2f = %.2f%n", num1, num2, num1 + num2);
                        break;
                    case "2":
                        System.out.printf("结果: %.2f - %.2f = %.2f%n", num1, num2, num1 - num2);
                        break;
                    case "3":
                        System.out.printf("结果: %.2f * %.2f = %.2f%n", num1, num2, num1 * num2);
                        break;
                    case "4":
                        if (num2 == 0) {
                            System.out.println("错误：除数不能为零");
                        } else {
                            System.out.printf("结果: %.2f / %.2f = %.2f%n", num1, num2, num1 / num2);
                        }
                        break;
                }
            } catch (NumberFormatException e) {
                System.out.println("错误：请输入有效的数字");
            } catch (Exception e) {
                System.out.println("发生错误: " + e.getMessage());
            }
        }

        scanner.close();
    }
}